#include "clkXmlElement.h"

clkXmlElement::clkXmlElement()
{
	m_parent = 0;
	m_child = 0;
	m_next = 0;
	m_prev = 0;
}

clkXmlElement::~clkXmlElement()
{

}

clkXmlAttribute* clkXmlElement::getAttribute(string a_name)
{
	if(!m_attributes.size()) return 0;
	for(int i=0;i<(int)m_attributes.size();i++)
	{
		if(m_attributes[i]->m_name == a_name)
			return m_attributes[i];
	}
	return 0;
}

clkXmlElement* clkXmlElement::getChild(string a_name)
{
	if(!m_child) return 0;
	clkXmlElement* ele = m_child;
	while(ele)
	{
		if(ele->m_name == a_name)
			return ele;
		else
			ele = ele->m_next;
	}
	return 0;
}

string clkXmlElement::getAttributeData(string a_name)
{
	clkXmlAttribute* att = getAttribute(a_name);
	if(att) return att->m_data;
	return string();
}

string clkXmlElement::getChildData(string a_name)
{
	clkXmlElement* ele = getChild(a_name);
	if(ele) return ele->m_data;
	return string();
}

vector<clkXmlElement*> clkXmlElement::getChildren(string a_name)
{
	vector<clkXmlElement*> vec;
	if(!m_child) return vec;
	clkXmlElement* ele = m_child;
	while(ele)
	{
		if(ele->m_name == a_name)
			vec.push_back(ele);
		ele = ele->m_next;
	}
	return vec;
}